package com.lagou.service.impl;

import com.lagou.common.Const;
import com.lagou.common.ServerResponse;
import com.lagou.mapper.IndustryMapper;
import com.lagou.service.IIndustryService;
import com.lagou.vo.ConverterVo;
import com.lagou.vo.IndustryTopVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class IndustryServiceImpl implements IIndustryService {
    @Autowired
    private IndustryMapper industryMapper;

    @Override
    public ServerResponse<Map<String, Object>> getCityValue() {
        List<ConverterVo> cityValue = industryMapper.getCityValue();
        Map<String,Object> cityValueMap = new HashMap<>();
        List<ConverterVo> thirdList = new ArrayList<>();
        List<ConverterVo> dataList = new ArrayList<>();
        List<String> cityList = new ArrayList<>();
        for (ConverterVo converterVo : cityValue) {
            if(thirdList.size() < 3){
                thirdList.add(converterVo);
            }
            dataList.add(converterVo);
            cityList.add(converterVo.getName());

        }
        cityValueMap.put("thridList",thirdList);
        cityValueMap.put("dataList",dataList);
        cityValueMap.put("cityNamesList",cityList);

        return ServerResponse.createBySuccessData(cityValueMap);
    }

    @Override
    public ServerResponse<Map<String, Object>> industryTop() {
        List<IndustryTopVo> industryTopVos = industryMapper.industryTop();
        Map<String,Object> topMap = new HashMap<>();
        List<String> names = new ArrayList<>();
        List<Long> num = new ArrayList<>();
        for (IndustryTopVo industryTopVo : industryTopVos) {
            names.add(industryTopVo.getPositionTypeName());
            num.add(industryTopVo.getNum());
        }
        topMap.put("names",names);
        topMap.put("count",num);
        return ServerResponse.createBySuccessData(topMap);

    }

    @Override
    public ServerResponse<Map<String, Object>> industryCompare() {
        Map<String,Object> compareMap = new HashMap<>();
        for (String industryType : Const.INDUSTRY_TYPE) {
            List<Long> num = new ArrayList<>();
            List<IndustryTopVo> industryTopVos = industryMapper.industryCompare(industryType, Const.START_DATE, Const.END_DATE);
            for (IndustryTopVo industryTopVo : industryTopVos) {
                num.add(industryTopVo.getNum());
            }
            if(Const.INDUSTRY_TYPE[0].equals(industryType)){
                compareMap.put("sell",num);
            } else if (Const.INDUSTRY_TYPE[1].equals(industryType)) {
                compareMap.put("server",num);
            } else {
                compareMap.put("pro",num);
            }
        }
        compareMap.put("dateTime",Const.DATE);
        compareMap.put("industryNameList",Const.INDUSTRY_TYPE);
        return ServerResponse.createBySuccessData(compareMap);
    }

    @Override
    public ServerResponse<Map<String, Object>> topTenSalary() {
        List<ConverterVo> converterVos = industryMapper.topTenSalary();
        Map<String,Object> topTenMap = new HashMap<>();
        List<String> names = new ArrayList<>();
        List<Integer> count = new ArrayList<>();
        for (ConverterVo converterVo : converterVos) {
            names.add(converterVo.getName());
            count.add(converterVo.getValue());
        }
        topTenMap.put("names",names);
        topTenMap.put("count",count);
        return ServerResponse.createBySuccessData(topTenMap);
    }
}
